//
//  JBWTabBarView.m
//  JBWDSK
//
//  Created by 崔志伟 on 2018/7/30.
//  Copyright © 2018年 崔志伟. All rights reserved.
//

#import "JBWTabBarView.h"
#import "UIButton+JBWTitleImgEdgeInsets.h"
@interface JBWTabBarView ()
@property (nonatomic,strong)   UIButton * informationBtn  ;
@property (nonatomic,strong)   UIButton * giftBtn  ;
@property (nonatomic,strong)   UIButton * meBtn  ;

@end

@implementation JBWTabBarView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self  = [super initWithFrame:frame]) {
        self.backgroundColor = JBW_HEX_COLOR(0x23262d);
        
        UIButton * mainBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 60, 60)];
        [mainBtn setImage:GetImageNamed(@"sdk_ic_log_all") forState:UIControlStateNormal];
        [self addSubview:mainBtn];
        
        UIButton * informationBtn= [[UIButton alloc]initWithFrame:CGRectMake(0, 60, 60, 60)];
        [informationBtn setTitle:@"资讯" forState:UIControlStateNormal];
        [self setBaseBtn:informationBtn selectImage:GetImageNamed(@"ic_news_pre") normalImgage:GetImageNamed(@"ic_news_nor")];
        informationBtn.tag = 200;
        [self addSubview:informationBtn];
        self.informationBtn = informationBtn;
        
        UIButton * giftBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 120, 60, 60)];
        [giftBtn setTitle:@"礼包" forState:UIControlStateNormal];
        [self setBaseBtn:giftBtn selectImage:GetImageNamed(@"ic_gift_pre") normalImgage:GetImageNamed(@"ic_gift_nor")];
        giftBtn.tag = 201;
        [self addSubview:giftBtn];
        self.giftBtn = giftBtn;
        
        UIButton * meBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 180, 60, 60)];
        [meBtn setTitle:@"我的" forState:UIControlStateNormal];
        meBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [meBtn setImage:GetImageNamed(@"ic_me_pre") forState:UIControlStateNormal];
        [self setBaseBtn:meBtn selectImage:GetImageNamed(@"ic_me_pre") normalImgage:GetImageNamed(@"ic_me_nor")];
        meBtn.tag = 202;
        [self addSubview:meBtn];
        self.meBtn = meBtn;
        
    }
    return self;
}

- (void)setBaseBtn:(UIButton *)btn selectImage:(UIImage *)selectImage normalImgage:(UIImage*) normalImgage{
    btn.titleLabel.font = [UIFont systemFontOfSize:12];
    [btn setTitleColor:JBW_HEX_COLOR(0xcd6c1d) forState:UIControlStateSelected];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setImage:selectImage forState:UIControlStateSelected];
    [btn setImage:normalImgage forState:UIControlStateNormal];
    [btn  layoutButtonTitleImageEdgeInsetsWithStyle:(JBWButtonEdgeInsetsStyleBottom) titleImgSpace:5];
    [btn addTarget:self action:@selector(selectBtnAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)setBtnDefault{
    self.informationBtn.selected = NO;
    self.giftBtn.selected = NO;
     self.meBtn.selected = NO;
}

-(void)setSelectIndex:(NSInteger)selectIndex{
    _selectIndex = selectIndex;
  
    switch (selectIndex) {
        case 0:
            {
                [self selectBtnAction: self.informationBtn];
            }
            break;
        case 1:
            {
                [self selectBtnAction: self.giftBtn];

            }
            break;
        case 2:
            {
                [self selectBtnAction: self.meBtn];
            }
            break;
        default:
            break;
    }
    
    
}

- (void)selectBtnAction:(UIButton *)sender{
    [self setBtnDefault];
    sender.selected = YES;
    if (self.selectItemBlock) {
        self.selectItemBlock(sender.tag -200);
    }
}

@end
